package org.sucri.servlet;

import org.sucri.dao.NewsEntity;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Wen Yu
 * Date: Sep 2, 2007
 * Time: 1:18:39 PM
 * To change this template use File | Settings | File Templates.
 */
public class Dao_Util
{
  static private EntityManagerFactory emf = null;

  public static void setEntityManagerFactory(EntityManagerFactory s) { emf = s; }

  public static List<NewsEntity> getNewsEntities(int limit)
  {
    if (emf == null) throw new RuntimeException("EntityManagerFactory not Initialized!");

    EntityManager em =  emf.createEntityManager();

    Query            query = em.createQuery("select e from NewsEntity e order by e.lastmodifyDate desc");
    List<NewsEntity> news  = query.getResultList();

    em.close();

    return news;
  }
}
